//
//  DepartmentViewController.m
//  DrProcessTable
//
//  Created by 白岩凇 on 2016/10/4.
//  Copyright © 2016年 白岩凇. All rights reserved.
//

#import "DepartmentViewController.h"
#import "DptmtCellModel.h"
#import "DepartmentCell.h"
#import "DoctorViewControllerTableViewController.h"
#import "MJExtension.h"
#import "GHNetWorkTools.h"

#define navigationTitle @"选择科室"
@interface DepartmentViewController ()
//模型数组

@end

@implementation DepartmentViewController

- (NSMutableArray *)models{
    
    NSMutableArray* modelsArray=[NSMutableArray array];
    //字典数组转模型数组 mjExtension框架
    modelsArray=[DptmtCellModel mj_objectArrayWithKeyValuesArray:_models];
    // modelsArray=[HsptCellModel mj_objectArrayWithKeyValuesArray:HsptInfoArray];
    _models=modelsArray;
    
    //        NSLog(@"--------------\n %@ \n-------------------",_models);
    //}
    return _models;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //self.navigationItem.title=self.mo;
    self.tableView.separatorInset=UIEdgeInsetsZero;
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark - Table view data source

//返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section    {
    return  self.models.count;
}

//返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {
    DepartmentCell *cell = [DepartmentCell cellWithTableView:tableView];
    cell.model=self.models[indexPath.row];
    
    // Configure the cell...
    
    return cell;
}
//返回行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    DptmtCellModel * model=self.models[indexPath.row];
    CGFloat need=model.h;
    return need;
}
//预估高度
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath  {
    return 200;
}


#warning 选择这一行后调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    DepartmentCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    
    // NSString *urlstr = [NSString stringWithFormat:@"department?HospitalName=%@",cell.model.HospitalName];
    
    
    
    
    
    
    
    
    NSString *urlstr = @"doctor";
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:cell.model.HospitalName,@"HospitalName",cell.model.DepartmentName,@"DepartmentName", nil];
    
    
    
    NSLog(@"%@",urlstr);
    [[GHNetWorkTools sharedTools] requestDataWith:GET urlString:urlstr parameters:dict finishedBlock:^(id result, NSError *error) {
        NSLog(@"%@",result);
        
        DoctorViewControllerTableViewController* need=[[DoctorViewControllerTableViewController alloc]init];
        
        need.models = [result valueForKey:@"Doctor"];
        need.title = cell.model.DepartmentName;
        //设置返回按钮样式
        self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
        [self.navigationController pushViewController:need animated:YES];
        
        
        
    }];
    

    
    
    
    
    
    
    //创建DepartmentViewController,push进导航控制器
   // DoctorViewControllerTableViewController * need=[[DoctorViewControllerTableViewController alloc]init];
    //设置返回按钮样式
  //  self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
   // [self.navigationController pushViewController:need animated:YES];
}



@end
